define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
    	index: function () {
			var ajax_page = function(page){
				var overtime='<tr><td colspan="10" style="text-align:center;">请求超时，<a href="javascript:;" class="overtime-trendLatestA" data-page="'+page+'">点击重试</a></td></tr>';
				$.ajax({
		            url:url,
		            type:'post',
		            data:'page='+page,
		            dataType: "json",
		            timeout: '10000',
		            beforeSend:function(){
		            	$('.visit-latest-tbody').html('<tr><td colspan="10" style="text-align: center;"><span><i class="fa fa-spin fa-spinner" aria-hidden="true"></i>&nbsp;&nbsp;数据获取中...<span></td></tr>');
		            },
		            success:function(res){
		            	if(res.status){
		            		$('.visit-latest-tbody').html(res.html);
		            		$('.visit-latest-page').html(res.page);
		            	}else{
		            		$('.visit-latest-tbody').html('<tr><td colspan="10" style="text-align:center;">'+res.msg+'</td></tr>');
		            	}
		            },
		            error:function(XMLHttpRequest, textStatus, errorThrown){
		                $('.visit-latest-tbody').html(overtime); 
		            },
		            complete: function (XMLHttpRequest, textStatus) {
		                if(textStatus == 'timeout'){
		                    $('.visit-latest-tbody').html(overtime);
		                }
		            },
		        });
			};
			$(document).on("click",".show-detail",function(){
				var obj=$(this);
				var key=obj.attr("data-key");
				var fa=obj.find('i');
			    var plus=fa.hasClass('fa-plus');
			    if(plus){
			        fa.removeClass('fa-plus');
			        fa.addClass('fa-minus');
			        $(".table_tr_"+key).show();
			    }else{
			        fa.removeClass('fa-minus');
			        fa.addClass('fa-plus');
			        $(".table_tr_"+key).hide();
			    }
			})
			if(bdtj_show==1){
				ajax_page(1);
			}else{
				layer.alert("尚未配置，请前往插件管理-百度网站统计-配置");
			}
			$(document).on("click",".overtime-trendLatestA,.ajax-page",function(){
				var page=$(this).attr("data-page");
				ajax_page(page);
			})
    	}
    };
    return Controller;
});